<%--
  Created by IntelliJ IDEA.
  User: 云哥
  Date: 2023/6/3
  Time: 16:09
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>个人图书管理</title>
    <style>
        #box {
            width: 400px;
            margin: 20px auto;
        }

        table {
            width: 100%;
        }

        h2 {
            text-align: center;
        }

        .add {
            color: red;
            text-decoration: none;
        }
    </style>
</head>
<body>
<div id="box">
    <h2>图书信息</h2>
    <table border="1" align="center">
        <tr bgcolor="#00bfff">
            <td>图书名称</td>
            <td>图书作者</td>
            <td>购买时间</td>
            <td>图书分类</td>
            <td>操作</td>
        </tr>
        <c:if test="${not empty requestScope.books}">
            <c:forEach items="${requestScope.books}" var="b" varStatus="vs">
                <tr
                        <c:if test="${vs.index%2!=0}">style="background-color: aqua"</c:if> >

                    <td>${b.name}</td>
                    <td>${b.author}</td>
                    <td>${b.time}</td>
                    <td>
                        <c:choose>
                            <c:when test="${b.type eq 1}">计算机/软件</c:when>
                            <c:when test="${b.type eq 2}">小说/文摘</c:when>
                            <c:otherwise>杂项</c:otherwise>
                        </c:choose>
                    </td>
                    <td><a href="javascript:" bid="${b.id}" name="del">删除</a></td>
                </tr>
            </c:forEach>
        </c:if>
        <c:if test="${empty requestScope.books}">
            <tr>
                <td colspan="6"><h2>暂无数据</h2></td>
            </tr>
        </c:if>
    </table>
    <a href="add.jsp" class="add">新增图书信息</a>

    <script src="js/jquery-1.12.4.js"></script>
    <script>
        $(function () {
            $('a[name=del]').click(function () {
                let bid = $(this).attr('bid');
                let $tr = $(this).parent().parent();
                if (confirm('确定删除编号为' + bid + '的图书吗？')) {
                    // $.post('deleteServlet',{bid:bid},function (data) {
                    //     if(data.code===200){
                    //         $tr.remove();
                    //     }
                    // })
                    $tr.remove();
                    $('table tr:odd').css('background-color', 'aqua');
                }
            });
        })
    </script>
</div>
</body>
</html>
